package com.lvy.hczn.front.business.controller;

import java.util.List;

import com.lvy.hczn.front.business.service.TransferOrderDetailService;
import com.lvy.hczn.front.system.domain.business.TransferOrderDetail;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.common.core.page.TableDataInfo;

/**
 * 调拨单明细Controller
 *
 * @author ruoyi
 * @date 2023-08-16
 */
@Controller
@RequestMapping("/system/transfer/detail")
public class TransferOrderDetailController extends BaseController {
    private String prefix = "system/transfer/detail";

    @Autowired
    private TransferOrderDetailService transferOrderDetailService;

    @RequiresPermissions("system:transfer:detail:view")
    @GetMapping()
    public String detail() {
        return prefix + "/detail";
    }

    /**
     * 查询调拨单明细列表
     */
    @RequiresPermissions("system:transfer:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TransferOrderDetail transferOrderDetail) {
        startPage();
        List<TransferOrderDetail> list = transferOrderDetailService.selectTransferOrderDetailList(transferOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出调拨单明细列表
     */
    @RequiresPermissions("system:transfer:detail:export")
    @Log(title = "调拨单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TransferOrderDetail transferOrderDetail) {
        List<TransferOrderDetail> list = transferOrderDetailService.selectTransferOrderDetailList(transferOrderDetail);
        ExcelUtil<TransferOrderDetail> util = new ExcelUtil<TransferOrderDetail>(TransferOrderDetail.class);
        return util.exportExcel(list, "调拨单明细数据");
    }

    /**
     * 新增调拨单明细
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存调拨单明细
     */
    @RequiresPermissions("system:transfer:detail:add")
    @Log(title = "调拨单明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TransferOrderDetail transferOrderDetail) {
        return toAjax(transferOrderDetailService.insertTransferOrderDetail(transferOrderDetail));
    }

    /**
     * 修改调拨单明细
     */
    @RequiresPermissions("system:transfer:detail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        TransferOrderDetail transferOrderDetail = transferOrderDetailService.selectTransferOrderDetailById(id);
        mmap.put("transferOrderDetail", transferOrderDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存调拨单明细
     */
    @RequiresPermissions("system:transfer:detail:edit")
    @Log(title = "调拨单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TransferOrderDetail transferOrderDetail) {
        return toAjax(transferOrderDetailService.updateTransferOrderDetail(transferOrderDetail));
    }

    /**
     * 删除调拨单明细
     */
    @RequiresPermissions("system:transfer:detail:remove")
    @Log(title = "调拨单明细", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(transferOrderDetailService.deleteTransferOrderDetailByIds(ids));
    }
}
